const person = {
  name: "John Doe",
  age: 42,
  nationality: "American"
};

// const personProxy = new Proxy(person, {
//   get: (obj, prop) => {
//     if (!obj[prop]) { // 获取属性时的容错处理
//       console.log(`Hmm.. this property doesn't seem to exist`);
//     } else {
//       console.log(`The value of ${prop} is ${Rz}`);
//     }
//   },
//   set: (obj, prop, value) => {
//     if (prop === "age" && typeof value !== "number") { // age字段检验
//       console.log(`Sorry, you can only pass numeric values for age.`);
//     } else if (prop === "name" && value.length < 2) { // name字段检验
//       console.log(`You need to provide a valid name.`);
//     } else {
//       console.log(`Changed ${prop}  from ${obj[prop]} to ${value}.`);
//       obj[prop] = value;
//     }
//     return true;
//   }
// });

const personProxy = new Proxy(person, {
  get: (obj, prop) => {
    console.log(`The value of ${prop} is ${Reflect.get(obj, prop)}`);
  },
  set: (obj, prop, value) => {
    console.log(`Changed ${prop} from ${obj[prop]} to ${value}`);
    Reflect.set(obj, prop, value);
  },
});


// personProxy.nonExistentProperty;
// personProxy.age = "44";
// personProxy.name = "";